/**
 * @Author: leibidong
 * @Description:商品分类管理
 * @File:  categoryHandler
 * @Version: 1.0.0
 * @Date: 2021/7/3 15:22
 */

package handler

import (
	"fmt"
	"ginProject/biz/service"
	"ginProject/biz/utils"
	"ginProject/biz/vo"
	"github.com/gin-gonic/gin"
)

/**
 * @Author leibidong
 * @Description 查询所有一级分类hander层
 * @Date  2021/7/4 19:19
 **/
func SelectAllFirstCategory(c *gin.Context) {
	first := service.QueryAllFirst()
	if len(first) != 0 {
		utils.ReturnOKMessage(first, c)
	} else {
		utils.ReturnFailureMessage(c, nil)
	}
}

/**
 * @Author leibidong
 * @Description 添加一级分类handler层
 * @Date  2021/7/4 19:20
 **/
func AddProductFirstCategory(c *gin.Context) {
	var name vo.FirstName
	c.ShouldBind(&name)
	service.InsertFirstCategory(name.Name)
	utils.ReturnOKMessage("ok", c)
}

/**
 * @Author leibidong
 * @Description 更改一级分类名字
 * @Date  2021/7/4 19:21
 **/
func UpdateProductFirstName(c *gin.Context) {
	var firstName vo.UpdateFirstName
	c.ShouldBind(&firstName)
	fmt.Println(firstName.ID, firstName.NewName)
	service.UpdateFirstName(firstName.ID, firstName.NewName)
	utils.ReturnOKMessage("ok", c)
}

/**
 * @Author leibidong
 * @Description 删除一级分类接口
 * @Date  2021/7/4 20:03
 **/
func DeleteFirstProductCategory(c *gin.Context) {
	s := c.Query("id")
	id := utils.StringToInt(s)
	service.DeleteFirstProductCategory(id)
	utils.ReturnOKMessage("ok", c)
}
